﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using MVCScaffolder;

/* Generated  */
namespace EDMXParserV1
{
    [Serializable]
    public class Property
    {
        public String Precision { get; set; }
        public String p1StoreGeneratedPattern { get; set; }
        public String Name { get; set; }
        public String Type { get; set; }
        public String Nullable { get; set; }
        public String StoreGeneratedPattern { get; set; }
        public String MaxLength { get; set; }
        public String Unicode { get; set; }
        public String FixedLength { get; set; }
        public String Scale { get; set; }

        public Sortable Sortable { get; set; }
        public Searchable Searchable { get; set; }

        // The way to show the column in the edit view
        // No, Edit, View 
        public String IsInDetailView { get; set; }

        // whether to show this column in the Master View
        public bool IsInMasterView { get; set; }

        public Boolean IsNullable()
        {
            if (Nullable == null)
                return true;
            if (Nullable.ToUpper() == "TRUE")
                return true;
            else
                return false;
        }

        public Boolean IsDateTime()
        {
            if (Type == "DateTime")
            {
                return true;
            }
            if (Type == "DateTime?")
            {
                return true;
            }
            return false;

        }

        public String FriendlyDisplayName()
        {
            String Result = Name.SpaceAfterCapitalLetters();

            if (Result.EndsWith(" I D"))
            {
                Result = Result.Substring(0, Result.Length - 2) + "D";
            }

            return Result;
        }


        public static Property New(System.Xml.XmlNode Node)
        {
            Property Property = new Property();

            foreach (XmlAttribute Attribute in Node.Attributes)
            {
                switch (Attribute.Name)
                {
                    case "Name":
                        Property.Name = Attribute.Value;
                        break;
                    case "Type":
                        Property.Type = Attribute.Value;
                        break;
                    case "Nullable":
                        Property.Nullable = Attribute.Value;
                        break;
                    case "MaxLength":
                        Property.MaxLength = Attribute.Value;
                        break;
                    case "StoreGeneratedPattern":
                        Property.StoreGeneratedPattern = Attribute.Value;
                        break;
                    case "annotation:StoreGeneratedPattern":
                        Property.StoreGeneratedPattern = Attribute.Value;
                        break;
                    case "Unicode":
                        Property.Unicode = Attribute.Value;
                        break;
                    case "FixedLength":
                        Property.FixedLength = Attribute.Value;
                        break;
                    case "p1:StoreGeneratedPattern":
                        Property.p1StoreGeneratedPattern = Attribute.Value;
                        break;
                    case "Precision":
                        Property.Precision = Attribute.Value;
                        break;
                    case "Scale":
                        Property.Scale = Attribute.Value;
                        break;
                    default:
                        Globals.AttributeSwitchCoder(Attribute);
                        break;
                }

            }

            foreach (XmlNode ChildNode in Node.ChildNodes)
            {
                switch (ChildNode.Name)
                {
                    default:
                        Globals.NodeSwitchCoder(ChildNode);
                        break;
                }
            }

            return Property;
        }
    }
}
